<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户中心</title>
    <link rel="stylesheet" type="text/css" href="../../static/news/css/reset.css">
    <link rel="stylesheet" type="text/css" href="../../static/news/css/jquery.pagination.css">
    <link rel="stylesheet" type="text/css" href="../../static/news/css/main.css">
    <script type="text/javascript" src="../../static/news/js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="../../static/news/js/jquery.pagination.min.js"></script>
</head>
<body class="inframe_body">
<div class="news_list">
    <h3>新闻列表</h3>
    <ul class="article_list">
        {% for news in collections -%}
            <li>
                <a href="javascript:;" data_newsid="{{ news.id }}" data-status="{{ news.status }}">{{ news.title }}</a>
                {% if news.status==0 %}
                    <em class="review">审核中</em>
                {% elif news.status==-1 %}
                    <em class="nopass">未通过</em>
                {% elif news.status==1 %}
                    <em class="pass">已通过</em>
                {% endif %}

                <span>{{ news.create_time }}</span>

                {% if news.status==-1 %}
                    <b>{{ news.reason }}</b>
                {% endif %}
            </li>
        {%- endfor %}
    </ul>

    <div id="pagination" class="page"></div>

    <script>
        $(function () {

            //全局网页跳转，不只是刷新iframe
            $('.article_list').delegate('a', 'click', function () {
                var news_id = $(this).attr('data_newsid');
                window.parent.location.href = "/" + news_id
            });


            // 分页功能
            $("#pagination").pagination({
                currentPage: {{ curr_page }},
                totalPage: {{ total_page }},
                callback: function (current) {
                    //window.location.href = "users/follow_list/" + current
                    $.ajax({
                        type: "GET",
                        url: "news_list?page=" + current,
                        dataType: "json",
                        success: function (resp) {
                            //拼接html(这个部分根据自己的需求去实现)
                            totalPage = resp.total_page
                            var newses = resp.collections;
                            //console.log(users);
                            var htm = '';

                            newses.forEach(function (news) {
                                htm += '<li><a href="javascript:;" data_newsid="' + news.id + '" data-status="' ;

                                htm += news.status + '">' + news.title + '</a>';

                                if (news.status==0){
                                    htm += '<em class="review">审核中</em>';
                                }else if (news.status==-1){
                                    htm += '<em class="nopass">未通过</em>';
                                }else if (news.status==1){
                                    htm += '<em class="pass">已通过</em>';
                                }

                                htm += '<span>' + news.create_time + '</span></li>';

                                if (news.status==-1) {
                                    htm += '<b>' + news.reason + '</b>';
                                }

                            });

                            $('.article_list').html(htm)
                        }
                    });
                }
            });
        });
    </script>

</div>
</body>
</html>